package com.baitengsoft.patentapimonitor.api.service.impl;

import com.baitengsoft.patentapimonitor.api.dao.*;
import com.baitengsoft.patentapimonitor.api.entity.*;
import com.baitengsoft.patentapimonitor.api.model.*;
import com.baitengsoft.patentapimonitor.api.service.RptPatentDataAreaService;
import com.baitengsoft.patentapimonitor.common.utils.DateUtils;
import com.baitengsoft.patentapimonitor.common.utils.IncreaseRateUtils;
import com.baitengsoft.patentapimonitor.common.utils.WebUtils;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.util.*;

/**
 * 专利创造指标分析服务实现
 *
 * @author Chen 2017/12/25
 */
@Service
public class RptPatentDataAreaServiceImpl extends BaseServiceImpl<RptPatentDataAreaEntity> implements RptPatentDataAreaService {

    @Autowired
    private RptpatentDataAreaDao rptpatentDataAreaDao;
    @Autowired
    private WebPlatFormAreaDao webPlatFormAreaDao;
    @Autowired
    private RptPatentIpcDao rptPatentIpcDao;
    @Autowired
    private RptInventorDao rptInventorDao;
    @Autowired
    private RptAgencyDao rptAgencyDao;

    /**
     * 有效发明 YXFMTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getValidIPatListByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "YXFMTotalNum");
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getYxfmtargetnum() != null && entity.getYxfmcompletionrate() != null) {
                info.setCompletionRate(entity.getYxfmcompletionrate());//完成率,当前月份的完成率
                info.setGoal(entity.getYxfmtargetnum().floatValue());//目标.当前月份的目标
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("YXFMTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("YXFMTotalNum", "YXFMTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 万人有效发明专利拥有量 YXFMWRTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getMillionIPatByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "YXFMWRTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getYxfmwrtargetnum() != null && entity.getYxfmwrcompletionrate() != null) {//改
                info.setGoal(entity.getYxfmwrtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getYxfmwrcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("YXFMWRTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("YXFMWRTotalNum", "YXFMWRTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 专利申请 ZLSQTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getPatApplyByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "ZLSQTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getZlsqtargetnum() != null && entity.getZlsqcompletionrate() != null) {//改
                info.setGoal(entity.getZlsqtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getZlsqcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("ZLSQTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("ZLSQTotalNum", "ZLSQTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 发明专利申请 FMSQTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getIpatApplyByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "FMSQTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getFmsqtargetnum() != null && entity.getFmsqcompletionrate() != null) {//改
                info.setGoal(entity.getFmsqtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getFmsqcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("FMSQTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("FMSQTotalNum", "FMSQTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 专利授权 SQZLTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getPatAuthorizeByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "SQZLTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getSqzltargetnum() != null && entity.getSqzlcompletionrate() != null) {//改
                info.setGoal(entity.getSqzltargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getSqzlcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("SQZLTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("SQZLTotalNum", "SQZLTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 发明专利授权 SQZLFMTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getIpatAuthorizeByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "SQZLFMTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getSqzlfmtargetnum() != null && entity.getSqzlfmcompletionrate() != null) {//改
                info.setGoal(entity.getSqzlfmtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getSqzlfmcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("SQZLFMTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("SQZLFMTotalNum", "SQZLFMTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 万人专利授权指数 SQZLWRTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getWRPatAuthorizeByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        if (areaIds == null || areaIds.size() < 1) return null;
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "SQZLWRTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getSqzlfmwrtargetnum() != null && entity.getSqzlfmwrcompletionrate() != null) {//改
                info.setGoal(entity.getSqzlfmwrtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getSqzlfmwrcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("SQZLWRTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("SQZLWRTotalNum", "SQZLWRTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 万人发明授权指数 SQZLFMWRTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getWRIpatAuthorizeByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        if (areaIds == null || areaIds.size() < 1) return infos;
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "SQZLFMWRTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getSqzlfmwrtargetnum() != null && entity.getSqzlfmwrcompletionrate() != null) {//改
                info.setGoal(entity.getSqzlfmwrtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getSqzlfmwrcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("SQZLFMWRTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("SQZLFMWRTotalNum", "SQZLFMWRTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 有效专利 YXZLTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getYXPatentByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "YXZLTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getYxzltargetnum() != null && entity.getYxzlcompletionrate() != null) {//改
                info.setGoal(entity.getYxzltargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getYxzlcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("YXZLTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("YXZLTotalNum", "YXZLTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 万人有效专利拥有量 YXZLWRTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getWRYXPatentByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "YXZLWRTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getYxfmwrtargetnum() != null && entity.getYxfmwrcompletionrate() != null) {//改
                info.setGoal(entity.getYxzlwrtargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getYxzlwrcompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("YXZLWRTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("YXZLWRTotalNum", "YXZLWRTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }

    /**
     * 实质审查 SZSCTotalNum
     */
    @Override
    public List<RptPatentDataAreaInfo> getSZSCByYear(Integer platformid, Integer year) {
        Integer selectedYear = getSelectYearByYear(year);
        Integer selectedDate = getSelectDateByYear(year);
        //根据平台id获取到区域ids
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        List<RptPatentDataAreaInfo> infos = new ArrayList<>();
        //遍历区域
        for (Integer areaId : areaIds) {
            //区域（要名称）
            WebPlatformareaEntity webPlatformareaEntity = webPlatFormAreaDao.selectByPrimaryKey(areaId);
            //根据选定年份和区域Id查询出该年份该区域的12个月的数据
            List<RptPatentDataAreaEntity> entities = getRptPatDataEntities(selectedYear, areaId);
            //处理报表数据
            RptPatentDataAreaInfo info = parseReportByDate(entities, selectedYear, "SZSCTotalNum");//改
            //查询当前月份的完成率
            RptPatentDataAreaEntity rptPatentDataAreaEntity = new RptPatentDataAreaEntity();
            rptPatentDataAreaEntity.setDateym(selectedDate);
            rptPatentDataAreaEntity.setAreaid(areaId);
            RptPatentDataAreaEntity entity = rptpatentDataAreaDao.selectOne(rptPatentDataAreaEntity);

            info.setAreaName(webPlatformareaEntity.getName());
            info.setCompletionRate(new BigDecimal(0));//完成率,当前月份的完成率
            info.setGoal(0f);//目标.当前月份的目标
            if (entity != null && entity.getSzsctargetnum() != null && entity.getSzsccompletionrate() != null) {//改
                info.setGoal(entity.getSzsctargetnum().floatValue());//目标.当前月份的目标 改
                info.setCompletionRate(entity.getSzsccompletionrate());//完成率,当前月份的完成率 改
            }
            infos.add(info);
        }
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("SZSCTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("SZSCTotalNum", "SZSCTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        infos.add(info);
        return infos;
    }


    /**
     * 历年趋势（type =0 申请，tyoe = 1 授权）
     */
    @Override
    public List<WebYearStatisticInfo> getTrendAnalysisList(Integer platformid, Integer type) {
        List<WebYearStatisticInfo> infos;
        if (type == 0) {
            infos = rptpatentDataAreaDao.getApplyTrendListByPlatformId(platformid);
        } else {
            infos = rptpatentDataAreaDao.getAuthorizeTrendListByPlatformId(platformid);
        }
        Map<Integer, BigDecimal> map = new LinkedHashMap<>();
        List<Integer> years = new ArrayList<>();
        for (WebYearStatisticInfo info : infos) {
            years.add(info.getYear());
            map.put(info.getYear(), new BigDecimal(info.getTotal()));
        }
        for (Integer year : years) {
            BigDecimal lastInfo = map.get(year - 1);
            if (lastInfo == null) {
                //没有去年数据，今年也没有
                map.replace(year, BigDecimal.ZERO);
            } else {
                BigDecimal lastYeartotal = map.get(year);
                map.replace(year, IncreaseRateUtils.getIncreaseRate(lastYeartotal, lastInfo));
            }
        }
        Set<Integer> infoYears = new HashSet<>();
        for (WebYearStatisticInfo info : infos) {
            info.setIncreaseRate(map.get(info.getYear()));
            infoYears.add(info.getYear());
        }
        Integer currentYear = DateUtils.getCurrentYear();
        //近十年
        for (int i = currentYear; i >= currentYear - 10; i--) {
            if (infoYears.contains(i)) {
                continue;
            }
            WebYearStatisticInfo info = new WebYearStatisticInfo();
            info.setYear(i);
            info.setWgsjcount(0);
            info.setSyxxcount(0);
            info.setTotal(0);
            info.setFmcount(0);
            info.setIncreaseRate(new BigDecimal(0));
            infos.add(info);
        }
        Collections.sort(infos);
        return infos;
    }

    /**
     * 概念页历年趋势
     */
    @Override
    public List<WebYearStatisticInfo> getTrendAnalysisListForHome(Integer platformid, Integer type) {
        List<WebYearStatisticInfo> infos;
        if (type == 0) {
            infos = rptpatentDataAreaDao.getApplyTrendListForHome(platformid);
        } else {
            infos = rptpatentDataAreaDao.getAuthorizeTrendListForHome(platformid);
        }
        for (WebYearStatisticInfo info : infos) {
            if (info.getTotal() == null) info.setTotal(0);
        }
        Integer currentYear = DateUtils.getCurrentYear();
        //近十年
        Set<Integer> infoYears = new HashSet<>();
        for (WebYearStatisticInfo info : infos) {
            infoYears.add(info.getYear());
        }
        for (int i = currentYear; i >= currentYear - 10; i--) {
            if (infoYears.contains(i)) {
                continue;
            }
            WebYearStatisticInfo info = new WebYearStatisticInfo();
            info.setYear(i);
            info.setWgsjcount(0);
            info.setTotal(0);
            info.setSyxxcount(0);
            info.setFmcount(0);
            info.setIncreaseRate(new BigDecimal(0));
            infos.add(info);
        }
        Collections.sort(infos);
        return infos;
    }

    /**
     * 历年趋势详情
     */
    @Override
    public List<WebYearStatisticInfo> getTrendDetailList(Integer platformid, Integer type, Integer selectYear) {
        List<WebYearStatisticInfo> infos = null;
        if (type == 0) {
            infos = rptpatentDataAreaDao.getApplyTrendListByPlatformIdAndYear(platformid, selectYear);
        } else {
            infos = rptpatentDataAreaDao.getAuthorizeTrendListByPlatformIdAndYear(platformid, selectYear);
        }
        Map<Integer, BigDecimal> map = new LinkedHashMap<>();
        List<Integer> years = new ArrayList<>();
        for (WebYearStatisticInfo info : infos) {
            years.add(info.getYear());
            map.put(info.getYear(), new BigDecimal(info.getTotal()));
        }
        for (Integer year : years) {
            BigDecimal lastInfo = map.get(year - 1);
            if (lastInfo == null) {
                map.replace(year, BigDecimal.ZERO);
            } else {
                BigDecimal lastYeartotal = map.get(year);
                map.replace(year, IncreaseRateUtils.getIncreaseRate(lastYeartotal, lastInfo));
            }
        }
        for (WebYearStatisticInfo info : infos) {
            info.setIncreaseRate(map.get(info.getYear()));
        }
        return infos;
    }

    /**
     * 有效专利区域统计
     */
    @Override
    public List<WebAreaStatisticInfo> getAreaAnalysislList(Integer platformid, String order, String sort) {
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        WebAreaStatisticInfo suminfo = new WebAreaStatisticInfo();
        if (areaIds == null || areaIds.size() < 1) return new ArrayList<>();
        List<WebAreaStatisticInfo> infos = rptpatentDataAreaDao.getWebAreaStatisticInfoByPlatFormId(platformid, DateUtils.getCurrentDate(), order, sort);
        suminfo.setAreaName("合计");
        suminfo.setFmcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setWgsjcount(0);
        suminfo.setTotal(0);
        suminfo.setAreaId(-1L);
        for (WebAreaStatisticInfo info : infos) {
            suminfo.setTotal(suminfo.getTotal() + info.getTotal());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + info.getWgsjcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + info.getSyxxcount());
            suminfo.setFmcount(suminfo.getFmcount() + info.getFmcount());
        }
        infos.add(0, suminfo);
        return infos;
    }

    @Override
    public List<WebAreaStatisticInfo> getAreaAnalysisAllList(Integer platformid, String order, String sort) {
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        WebAreaStatisticInfo suminfo = new WebAreaStatisticInfo();
        if (areaIds == null || areaIds.size() < 1) return new ArrayList<>();
        List<WebAreaStatisticInfo> infos = rptpatentDataAreaDao.getWebAreaStatisticAllInfoByPlatFormId(platformid, order, sort);
        suminfo.setAreaName("合计");
        suminfo.setFmcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setWgsjcount(0);
        suminfo.setTotal(0);
        for (WebAreaStatisticInfo info : infos) {
            suminfo.setTotal(suminfo.getTotal() + info.getTotal());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + info.getWgsjcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + info.getSyxxcount());
            suminfo.setFmcount(suminfo.getFmcount() + info.getFmcount());
        }
        infos.add(0, suminfo);
        return infos;
    }

    /**
     * IPC管理
     */
    @Override
    public List<WebIPCAnalysisInfo> getIPCAnalysisList(Integer platformid, String order, String sort) {

        Example example = new Example(RptPatentIpcEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("platformid", platformid);
        if (StringUtils.isNotBlank(order) && StringUtils.isNotBlank(sort)) {
            if (sort.equals("fmcount")) {
                example.setOrderByClause("YXFMCount" + " " + order);
            } else if (sort.equals("syxxcount")) {
                example.setOrderByClause("YXSYCount" + " " + order);
            } else if (sort.equals("wgsjcount")) {
                example.setOrderByClause("YXWGCount" + " " + order);
            } else if (sort.equals("total")) {
                example.setOrderByClause("YXHZCount" + " " + order);
            }
        }
        List<RptPatentIpcEntity> entities = rptPatentIpcDao.selectByExample(example);
        List<WebIPCAnalysisInfo> infos = new ArrayList<>();
        WebIPCAnalysisInfo suminfo = new WebIPCAnalysisInfo();
        suminfo.setFmcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setWgsjcount(0);
        suminfo.setTotal(0);
        suminfo.setIpcName("合计");
        for (RptPatentIpcEntity entity : entities) {
            WebIPCAnalysisInfo info = new WebIPCAnalysisInfo();
            if (entity.getCode() != null && entity.getName() != null)
                info.setIpcName(entity.getCode() + " : " + entity.getName());
            else
                info.setIpcName("");
            info.setFmcount(entity.getYxfmcount());
            info.setSyxxcount(entity.getYxsycount());
            info.setWgsjcount(entity.getYxwgcount());
            info.setTotal(entity.getYxhzcount());
            suminfo.setFmcount(suminfo.getFmcount() + entity.getYxfmcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + entity.getYxsycount());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + entity.getYxwgcount());
            suminfo.setTotal(suminfo.getTotal() + entity.getYxhzcount());
            infos.add(info);
        }
        infos.add(0, suminfo);
        return infos;
    }

    /**
     * 发明人统计
     */
    @Override
    public List<WebInventorAnalysisInfo> getInventorAnalysislList(Integer platformid) {
        Example example = new Example(RptInventorEntity.class);
        Example.Criteria criteria = example.createCriteria();
        example.setOrderByClause("yxhzcount desc");
        criteria.andEqualTo("platformid", platformid);
        PageHelper.startPage(0, 10);
        List<RptInventorEntity> entities = rptInventorDao.selectByExample(example);
        List<WebInventorAnalysisInfo> infos = new ArrayList<>();
        WebInventorAnalysisInfo suminfo = new WebInventorAnalysisInfo();
        suminfo.setTotal(0);
        suminfo.setWgsjcount(0);
        suminfo.setSyxxcount(0);
        suminfo.setFmcount(0);
        suminfo.setInventorName("合计");
        for (RptInventorEntity entity : entities) {
            WebInventorAnalysisInfo info = new WebInventorAnalysisInfo();
            info.setInventorName(entity.getInventorname());
            info.setFmcount(entity.getYxfmcount());
            info.setSyxxcount(entity.getYxsycount());
            info.setWgsjcount(entity.getYxwgcount());
            info.setTotal(entity.getYxhzcount());
            suminfo.setFmcount(suminfo.getFmcount() + info.getFmcount());
            suminfo.setSyxxcount(suminfo.getSyxxcount() + info.getSyxxcount());
            suminfo.setWgsjcount(suminfo.getWgsjcount() + info.getWgsjcount());
            suminfo.setTotal(suminfo.getTotal() + info.getTotal());
            infos.add(info);
        }
        infos.add(0, suminfo);
        return infos;
    }

    /**
     * 代理机构
     */
    @Override
    public List<WebAgencyAnalysisInfo> getAgencyAnalysislList(Integer platformid, Integer type) {
        Example example = new Example(RptAgencyEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("datatype", type);
        criteria.andEqualTo("platformid", platformid);
        example.setOrderByClause("yxhzcount desc");
        PageHelper.startPage(0, 10);
        List<RptAgencyEntity> entities = rptAgencyDao.selectByExample(example);
        List<WebAgencyAnalysisInfo> infos = new ArrayList<>();
        for (RptAgencyEntity entity : entities) {
            WebAgencyAnalysisInfo info = new WebAgencyAnalysisInfo();
            info.setAgencyName(entity.getAgencyname());
            info.setApplicantCount(entity.getApplicantcount());
            info.setFmcount(entity.getYxfmcount());
            info.setSyxxcount(entity.getYxsycount());
            info.setWgsjcount(entity.getYxwgcount());
            info.setTotal(entity.getYxhzcount());
            infos.add(info);
        }
        return infos;
    }

    @Override
    public List<WebAgencyAnalysisInfo> getAgencyAnalysislAllList(Integer platformid, Integer type) {
        Example example = new Example(RptAgencyEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("datatype", type);
        criteria.andEqualTo("platformid", platformid);
        example.setOrderByClause("yxhzcount desc");
        List<RptAgencyEntity> entities = rptAgencyDao.selectByExample(example);
        List<WebAgencyAnalysisInfo> infos = new ArrayList<>();
        for (RptAgencyEntity entity : entities) {
            WebAgencyAnalysisInfo info = new WebAgencyAnalysisInfo();
            info.setAgencyName(entity.getAgencyname());
            info.setApplicantCount(entity.getApplicantcount());
            info.setSyxxcount(entity.getYxsycount());
            info.setFmcount(entity.getYxfmcount());
            info.setWgsjcount(entity.getYxwgcount());
            info.setTotal(entity.getYxhzcount());
            infos.add(info);
        }
        return infos;
    }

    @Override
    public RptPatentDataAreaInfo getMillionIPatMonthInfo(Integer platformid) {
        List<Integer> areaIds = webPlatFormAreaDao.selectAreaIdByPlatFormId(platformid);
        Integer selectedYear = getSelectYearByYear(0);
        Integer selectedDate = getSelectDateByYear(0);
        List<RptPatentDataAreaSumInfo> suminfos = rptpatentDataAreaDao.getRptSumDataBySelectYear("YXZLWRTotalNum", selectedYear + "%", areaIds);
        RptPatentDataAreaInfo info = parseSumReportByDate(suminfos, selectedYear);
        RptPatentDataAreaSumInfo suminfo = rptpatentDataAreaDao.getRptSumDataBySelectDate("YXZLWRTotalNum", "YXZLWRTargetNum", selectedDate, areaIds);
        info.setCompletionRate(new BigDecimal(0));
        info.setGoal(0f);
        if (suminfo != null) {
            info.setGoal(suminfo.getTargetsum());  //当前月份的总目标
            info.setCompletionRate(getCompletionRate(suminfo));//当前月份的完成率
        }
        return info;
    }

    /**
     * 根据时间范围获取有效发明合计
     */
    @Override
    public Integer getYXFMCountByDateYM(Integer platformid, Integer dateYM) {
        if (dateYM == null) return 0;
        return rptpatentDataAreaDao.getYXFMCountByDateYM(platformid, dateYM);
    }

    /**
     * 获取有效专利区域分析
     */
    @Override
    public List<WebAreaStatisticInfo> getYXAreaAnalysis(Integer platformid) {
        List<WebAreaStatisticInfo> infos = rptpatentDataAreaDao.getWebAreaStatisticInfoByPlatFormId(platformid, DateUtils.getCurrentDate(), null, null);
        return infos;
    }

    /**
     * 获取总完成率
     * 当前年月的所有区域的总和/所有区域的目标总和
     */
    private BigDecimal getCompletionRate(RptPatentDataAreaSumInfo suminfo) {
        if (suminfo == null) {
            return new BigDecimal(0);
        }
        if (suminfo.getSum() == null || suminfo.getTargetsum() == null) {
            return new BigDecimal(0);
        }
        if (suminfo.getTargetsum() != 0.0) {
            //当前年月的 所有区域的总和/所有区域的目标总和
            BigDecimal decimal = new BigDecimal(suminfo.getSum() / suminfo.getTargetsum() * 100);
            BigDecimal setScale = decimal.setScale(2, BigDecimal.ROUND_HALF_DOWN);
            return setScale;
        } else {
            return new BigDecimal(0);
        }
    }

    /**
     * 生成报表信息
     */
    private RptPatentDataAreaInfo parseReportByDate(List<RptPatentDataAreaEntity> entities, Integer selectedYear, String type) {
        RptPatentDataAreaInfo info = new RptPatentDataAreaInfo();
        if (entities == null || entities.size() < 1) {
            return info;
        }
        info.setAreaId(entities.get(0).getAreaid());// 设置区域Id
        for (RptPatentDataAreaEntity entity : entities) {
            String year = String.valueOf(entity.getDateym());
            //获取指定区域的1月到12月的数据
            if (year.equals(selectedYear + "01")) {
                info.setJan(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "02")) {
                info.setFeb(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "03")) {
                info.setMar(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "04")) {
                info.setApr(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "05")) {
                info.setMay(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "06")) {
                info.setJune(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "07")) {
                info.setJuly(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "08")) {
                info.setAug(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "09")) {
                info.setSetp(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "10")) {
                info.setOct(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "11")) {
                info.setNov(getValueByType(entity, type));
            } else if (year.equals(selectedYear + "12")) {
                info.setDec(getValueByType(entity, type));
            }
        }
        return info;
    }

    /**
     * 根据type筛选要查询的值
     */
    private Float getValueByType(RptPatentDataAreaEntity entity, String type) {
        if (type.equals("YXFMTotalNum")) {
            return entity.getYxfmtotalnum().floatValue();
        } else if (type.equals("YXZLWRTotalNum")) {
            return entity.getYxzlwrtotalnum().floatValue();
        } else if (type.equals("ZLSQTotalNum")) {
            return entity.getZlsqtotalnum().floatValue();
        } else if (type.equals("FMSQTotalNum")) {
            return entity.getFmsqtotalnum().floatValue();
        } else if (type.equals("SQZLTotalNum")) {
            return entity.getSqzltotalnum().floatValue();
        } else if (type.equals("SQZLFMTotalNum")) {
            return entity.getSqzlfmtotalnum().floatValue();
        } else if (type.equals("SQZLFMWRTotalNum")) {
            return entity.getSqzlfmwrtotalnum().floatValue();
        } else if (type.equals("SQZLWRTotalNum")) {
            return entity.getSqzlwrtotalnum().floatValue();
        } else if (type.equals("YXZLTotalNum")) {
            return entity.getYxzltotalnum().floatValue();
        } else if (type.equals("YXFMWRTotalNum")) {
            return entity.getYxfmwrtotalnum().floatValue();
        } else if (type.equals("SZSCTotalNum")) {
            return entity.getSzsctotalnum().floatValue();
        }
        return 0f;
    }

    /**
     * 生成汇总信息
     */
    private RptPatentDataAreaInfo parseSumReportByDate(List<RptPatentDataAreaSumInfo> entities, Integer selectedYear) {
        RptPatentDataAreaInfo info = new RptPatentDataAreaInfo();
        info.setAreaName("合计");
        if (entities == null || entities.size() < 1) {
            return info;
        }
        for (RptPatentDataAreaSumInfo entity : entities) {
            String year = String.valueOf(entity.getDateYm());
            if (year.equals(selectedYear + "01")) {
                info.setJan(entity.getSum());
            } else if (year.equals(selectedYear + "02")) {
                info.setFeb(entity.getSum());
            } else if (year.equals(selectedYear + "03")) {
                info.setMar(entity.getSum());
            } else if (year.equals(selectedYear + "04")) {
                info.setApr(entity.getSum());
            } else if (year.equals(selectedYear + "05")) {
                info.setMay(entity.getSum());
            } else if (year.equals(selectedYear + "06")) {
                info.setJune(entity.getSum());
            } else if (year.equals(selectedYear + "07")) {
                info.setJuly(entity.getSum());
            } else if (year.equals(selectedYear + "08")) {
                info.setAug(entity.getSum());
            } else if (year.equals(selectedYear + "09")) {
                info.setSetp(entity.getSum());
            } else if (year.equals(selectedYear + "10")) {
                info.setOct(entity.getSum());
            } else if (year.equals(selectedYear + "11")) {
                info.setNov(entity.getSum());
            } else if (year.equals(selectedYear + "12")) {
                info.setDec(entity.getSum());
            }
        }
        return info;
    }

    /**
     * 获取指定年份，指定区域Id的 专利创造指标分析实体类
     */
    private List<RptPatentDataAreaEntity> getRptPatDataEntities(Integer selectedYear, Integer areaId) {
        Example example = new Example(RptPatentDataAreaEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("dateym", "%" + selectedYear + "%");
        criteria.andEqualTo("areaid", areaId);
        return rptpatentDataAreaDao.selectByExample(example);
    }

    /**
     * 根据前端值获取选中年
     */
    private Integer getSelectYearByYear(Integer year) {
        Integer selectedYear = DateUtils.getLastYear();
        if (year == 1) {
            selectedYear = DateUtils.getCurrentYear();//今年的年份
        }
        return selectedYear;
    }

    /**
     * 根据前端值获取选中月
     */
    private Integer getSelectDateByYear(Integer year) {
        Integer selectedDate = DateUtils.getCurrentDate();
        if (year == 0) {
            selectedDate = DateUtils.getLastYearDate();
        }
        return selectedDate;
    }
}


